import 'package:flutter/material.dart';
import 'package:hotfil_pub_web/lang/translation_service.dart';
import 'package:hotfil_pub_web/shared/sputils.dart';
import 'package:hotfil_pub_web/widgets/IconFontIcons.dart';
import 'package:hotfil_pub_web/widgets/my_sliver.dart';
import 'package:hotfil_pub_web/widgets/my_theme.dart';
import 'package:hotfil_pub_web/widgets/options_base.dart';
import 'package:get/get.dart';
import 'package:velocity_x/velocity_x.dart';

class LangItem extends StatelessWidget {
  final String langText;
  final bool isActive;

  const LangItem({Key? key, this.langText = '简体中文', this.isActive = false})
      : super(key: key);
  @override
  Widget build(BuildContext context) {
    return OptionsItemBase(
        handle: () {
          if (isActive) {
            return;
          }

          if (langText == '简体中文') {
            TranslationService.updateLocaleToTW();
          } else {
            TranslationService.updateLocaleToEN();
          }
        },
        child: Row(
          children: [
            Expanded(
              child: Text(
                langText,
                style: TextStyle(color: MyTheme.mainTextColor, fontSize: 14),
              ),
            ),
            Icon(
              IconFontIcons.iconXuanze,
              size: 20,
              color: isActive ? MyTheme.primaryColor : MyTheme.disabledColor,
            )
          ],
        ));
  }
}

class LangSelectPage extends StatefulWidget {
  @override
  State<LangSelectPage> createState() => _LangSelectPageState();
}

class _LangSelectPageState extends State<LangSelectPage> {
  @override
  void initState() {
    // TODO: implement initState
    super.initState();
    print(Get.locale.toString());
  }

  @override
  Widget build(BuildContext context) {
    return Scaffold(
      appBar: AppBar(
        title: 'qhyy'.tr.text.make(),
      ),
      body: Column(
        children: [
          MySLiver(),
          OptionsBase(
            children: [
              LangItem(
                langText: '简体中文',
                isActive: TranslationService.isTwLang,
              ),
              LangItem(
                langText: 'English',
                isActive: TranslationService.isENLang,
              )
            ],
          )
        ],
      ),
    );
  }
}
